<?php 
	session_start(); 
	include('./langues/francais.php');
	
	try
	{
		$bdd = new PDO('mysql:host=localhost;dbname=unmei', 'root', '');
	}
	catch(Exception $e)
	{
		die('Erreur : '.$e->getMessage());
	}
	$req = $bdd->query('SELECT * FROM admin_config');
	$config = $req->fetch();
	$nombre_articles_page=$config['nombre_articles'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<html>
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="./styles/style.css" />
        <!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
		
		<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
		<script type="text/javascript">
		tinyMCE.init({
			// General options
			mode : "textareas",
			theme : "advanced",
			plugins : "table,inlinepopups",

			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,|,table,removeformat,code",
			theme_advanced_buttons2 : "",
			theme_advanced_buttons3 : "",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "bottom",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "top",
			theme_advanced_resizing : true,

			// Example content CSS (should be your site CSS)
			content_css : "./style_editeur.css",

			// Style formats
			style_formats : [
				{title : 'Bold text', inline : 'b'},
				{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
				{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
				{title : 'Example 1', inline : 'span', classes : 'example1'},
				{title : 'Example 2', inline : 'span', classes : 'example2'},
				{title : 'Table styles'},
				{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
			],

			formats : {
				alignleft : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'left'},
				aligncenter : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'center'},
				alignright : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'right'},
				alignfull : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'full'},
				bold : {inline : 'span', 'classes' : 'bold'},
				italic : {inline : 'span', 'classes' : 'italic'},
				underline : {inline : 'span', 'classes' : 'underline', exact : true},
				strikethrough : {inline : 'del'},
				customformat : {inline : 'span', styles : {color : '#00ff00', fontSize : '20px'}, attributes : {title : 'My custom format'}}
			}
		});
		</script>

        <title><?php echo $config['nom'] . ', ' . $config['slogan']; ?></title>
    </head>
    
    <!--[if IE 6 ]><body class="ie6 old_ie"><![endif]-->
    <!--[if IE 7 ]><body class="ie7 old_ie"><![endif]-->
    <!--[if IE 8 ]><body class="ie8"><![endif]-->
    <!--[if IE 9 ]><body class="ie9"><![endif]-->
    <!--[if !IE]><!--><body><!--<![endif]-->
	
	<?php

	
	if (isset($_GET['page'])) 
	{
		$page=$_GET['page'];

		switch ($page)
		{
			case 'connexion':
				$req = $bdd->prepare('SELECT id,groupe_id FROM membres WHERE identifiant = :identifiant AND motdepasse = :motdepasse');
				$req->execute(array(
					'identifiant' => $_POST['identifiant'],
					'motdepasse' => $_POST['motdepasse']));
					$resultat = $req->fetch();
				if (!$resultat)
				{
					echo 'Mauvais identifiant ou mot de passe !';
				}
				else
				{
					$_SESSION['membre_id'] = $resultat['id'];
					$_SESSION['groupe'] = $resultat['groupe_id'];
					$_SESSION['identifiant'] = $_POST['identifiant'];;
				}
			break;
			case 'deconnexion':
				//echo "deconnexion";
				$_SESSION = array();
				session_destroy();
			break;
			default:
				// Page par defaut, est redirigée vers page=articles via le else
			break;
		}
	}
	else // Il manque des paramètres, on avertit le visiteur
	{
		echo 'Aucune action donc afficher par défaut';
		header('Location: page.php?page=articles');
	}
	?>
	
	
	<div id="bordure">
		<header>
            <div id="titre_principal">
                <img src="<?php echo $config['image_logo']; ?>" alt="Logo" id="logo" />
                <h1><?php echo $config['nom']; ?></h1>
                <h2><?php echo $config['slogan']; ?> : <?php echo $page; ?></h2>
            </div>
			<div id="connexion">
				<?php
				if (isset($_SESSION['identifiant']))
				{
					echo BONJOUR . ' ' . $_SESSION['identifiant'];
					?>
					<br />
					<a href="page.php?page=deconnexion"><?php echo SE_DECONNECTER; ?></a>
					<?php
				}
				else
				{
					?>
					<form method="post" action="page.php?page=connexion">
						<p>
						<label for="identifiant"><?php echo IDENTIFIANT; ?></label>  : <input type="text" name="identifiant" id="identifiant" placeholder="Identifiant de connexion" size="20" maxlength="10" /><br />
						<label for="motdepasse"><?php echo MOT_DE_PASSE; ?></label>  : <input type="password" name="motdepasse" id="motdepasse" placeholder="Mot de passe de connexion" size="20" maxlength="10" /><br />
						<input type="submit" value="<?php echo SE_CONNECTER; ?>" /> <input type="checkbox" name="souvenir" id="souvenir" checked /> <label for="souvenir"><?php echo RESTER_CONNECTE; ?></label>
						<p><a href="page.php?page=<?php echo INSCRIPTION; ?>"><?php echo INSCRIPTION; ?></a> | <a href="#"><?php echo IDENTIFIANTS_PERDUS; ?></a></p>
						</p>
					</form>
					<?php 
				}
				?>  
            </div> 
        </header>
	</div>
	<br />
	
	<div id="bordure">
		<nav>
			<ul>
				<li><a href="page.php">Infos</a></li>
				<li><a href="#">Contexte</a></li>
				<li><a href="page.php?page=admin_index">Administration</a></li>
				<li><a href="page.php?page=faq">FAQ</a></li>
				<li><a href="#">Contact</a></li>
			</ul>
		</nav>
	</div>
	<br />
	
	<div id="bordure">
		<div id="bloc_page">
            <section>
				<article>
					<div id="artcolgauche">
						<?php
						$prefixe=substr($page,0,5); 
						if ($prefixe=='admin')
							$menu = './admin/' . $prefixe . '_menu.php';
						else
							$menu = 'menu.php';
						include ($menu);
						?>
					</div>
			
					<div id="artcoldroit">
						<?php
						$prefixe=substr($page,0,5); 
						if ($prefixe=='admin')
							$module = './admin/' . $page . '.php';
						else
							$module = './modules/'  .$page . '.php';
							
						
						switch ($page)
						{
							case $page:
								include ($module);
							break;
							case $articles:
								$numero_page=$_GET['numero_page'];
								include ('page.php?page=articles&numero_page=$numero_page');
							break;
							case $admin_articles:
								$numero_page=$_GET['numero_page'];
								include ('page.php?page=admin_articles&numero_page=$numero_page');
							break;
							default:
								include ('./modules/articles.php');
							break;
						}
						?>
					</div>
				</article>
			
				<aside>
					<?php
					switch ($page)
					{
						case 'admin_stats':
								echo TEXTE_STATISTIQUES; 
							break;
							
						case 'lire':
							include ('./modules/chat_salons.php');
						break;
						
						case 'inscription':
							echo TEXTE_INSCRIPTION;
						break;
						
						case 'admin_clans':
							echo TEXTE_ADMIN_CLANS;
						break;
						
						case 'admin_races':
							echo TEXTE_ADMIN_RACES;
						break;
						case 'admin_mondes':
							echo TEXTE_ADMIN_MONDES;
						break;
						case 'admin_groupes':
							echo TEXTE_ADMIN_GROUPES;
						break;
						case 'admin_membres':
							echo TEXTE_ADMIN_MEMBRES;
						break;
						

						default:
							echo "Résumé des évènements";
						break;
					}
					?>
				</aside>
			</section>
		</div> <!-- Bloc page -->
	</div>
	<br />
	
	<div id="bordure">
		<nav>
			<ul>
				<li><a href="#">Fiche</a></li>
				<li><a href="page.php?page=chroniques">Chroniques</a></li>
				<li><a href="#">Personnages</a></li>
				<li><a href="#">Monde</a></li>
			</ul>
		</nav>
	</div>
	<br />
	
	<footer>
		<div id="bordureblockgauche">
			<div id="blockgauche">
				<h1>Actions récentes</h1>
				<p>12/05 20:15 - Discussion sur la Grand place.</p>
				<p>12/05 20:10 - Duel a l'entrée du village.</p>
			</div>
		</div>
		
		<div id="bordureblockdroit">
			<div id="blockdroit">
				<h1>Block droit</h1>
				<ul>
					<li><a href="#">Pupi le lapin</a></li>
					<li><a href="#">Mr Baobab</a></li>
					<li><a href="#">Kaiwaii</a></li>
					<li><a href="#">Perceval.eu</a></li>
				</ul>
			</div>
		</div>
		<div id="blockcentre">
			<p><a href="#"><img src="images/Pirate Icon 4_256x256-32.png" alt="Missions" /></a><a href="#"><img src="images/Pirate Icon 7_256x256-32.png" alt="Récompenses" /></a><a href="#"><img src="images/Pirate Icon 2_256x256-32.png" alt="Combats" /></a><a href="#"><img src="images/bg.png" alt="Chroniques" /></a><a href="#"><img src="images/bg.png" alt="Chroniques" /></a></p>
			<p><a href="#"><img src="images/Pirate Icon 4_256x256-32.png" alt="Missions" /></a><a href="#"><img src="images/Pirate Icon 7_256x256-32.png" alt="Récompenses" /></a><a href="#"><img src="images/Pirate Icon 2_256x256-32.png" alt="Combats" /></a><a href="#"><img src="images/bg.png" alt="Chroniques" /></a><a href="#"><img src="images/bg.png" alt="Chroniques" /></a></p>
		</div>
	</footer>

	<div id="copyright">
		<p><?php echo $config['pied']; ?></p>
	</div>
</body>
</html>
